package com.ymttest.database.sqlwapper.sqdistributor;

import java.util.HashMap;
import java.util.List;

import com.ymt.database.SqlManager;
import com.ymttest.database.model.sqdistributor.DistributionAgencyProductCategoryCommissionRate;

public class DistributionAgencyProductCategoryCommissionRateWrapper {
	
	SqlManager manager;

	public DistributionAgencyProductCategoryCommissionRateWrapper() {
		manager = new SqlManager("sqdistributor");
	}

	@SuppressWarnings("unchecked")
	public DistributionAgencyProductCategoryCommissionRate selectByPrimaryKey(Long id) {

		DistributionAgencyProductCategoryCommissionRate distributionAgencyProductCategoryCommissionRate = null;
		List<DistributionAgencyProductCategoryCommissionRate> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqdistributor.DistributionAgencyProductCategoryCommissionRateMapper.selectByPrimaryKey",
						id);
		manager.commit();

		if (result.size() > 0) {
			distributionAgencyProductCategoryCommissionRate = result.get(0);
		}

		return distributionAgencyProductCategoryCommissionRate;
	}
	
	@SuppressWarnings("unchecked")
	public DistributionAgencyProductCategoryCommissionRate selectByMerchangIdAndCategoryId(
			Long merchantId, Long firstCategoryId, Long secondCategoryId) {

		HashMap<String, Long> map = new HashMap<>();

		map.put("merchant_id", merchantId);
		map.put("first_category_id", firstCategoryId);
		map.put("second_category_id", secondCategoryId);

		DistributionAgencyProductCategoryCommissionRate distributionAgencyProductCategoryCommissionRate = null;

		List<DistributionAgencyProductCategoryCommissionRate> result = manager
				.getSelectResults(
						"com.ymttest.database.mapping.sqdistributor.DistributionAgencyProductCategoryCommissionRateMapper.selectByMerchangIdAndCategoryId",
						map);
		manager.commit();

		if (result.size() > 0) {
			distributionAgencyProductCategoryCommissionRate = result.get(0);
		}

		return distributionAgencyProductCategoryCommissionRate;
	}
		
	public static void main(String[] args) {
		
		DistributionAgencyProductCategoryCommissionRateWrapper test = new DistributionAgencyProductCategoryCommissionRateWrapper();

		System.out.println(test.selectByMerchangIdAndCategoryId(502593052L,
				1001L, 1002L).getCommission_rate());
	}
}
